/**
 * 
 */
package calculation.passed2;

/**
 * @author michael
Compare two version numbers version1 and version1.
If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.

You may assume that the version strings are non-empty and contain only digits and the . character.
The . character does not represent a decimal point and is used to separate number sequences.
For instance, 2.5 is not "two and a half" or "half way to version three", it is the fifth second-level revision of the second first-level revision.

Here is an example of version numbers ordering:

0.1 < 1.1 < 1.2 < 13.37
 */
public class CompareVersionNumbers {

	/**
	 * 
	 */
	public CompareVersionNumbers() {
		// TODO Auto-generated constructor stub
	}

    public int compareVersion(String version1, String version2) {
    	String[] subVersions1 = version1.split("\\.");
    	String[] subVersions2 = version2.split("\\.");
    	
    	int size = Math.max(subVersions1.length, subVersions2.length);
    	for (int i = 0; i < size; i++) {
    		Integer subVersion1 = i < subVersions1.length ? Integer.valueOf(subVersions1[i]) : 0;
    		Integer subVersion2 = i < subVersions2.length ? Integer.valueOf(subVersions2[i]) : 0;
    		if (subVersion1 != subVersion2) {
    			return subVersion1.compareTo(subVersion2);
    		}
//    		int compare = subVersion1.compareTo(subVersion2);
//    		if (compare != 0) {
//    			return compare;
//    		}
    	}
    	
    	return 0;
    }	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
